<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/template.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core">


    <ui:define name="title">
        <h:outputText value="#{bundle.ListProjectTitle}"></h:outputText>
    </ui:define>
    <ui:define name="body">
        <h:form id="form" styleClass="form list">
            <p:fieldset legend="Project Control" id="user_create">
                <c:if test="#{userController.allowedGroups('2') or userController.myselftEditing}">
                    <p:commandButton icon="ui-icon-plus" ajax="false" action="#{projectController.prepareCreate}" value="New Project" />
                </c:if>
                <p:separator/>
                <p:dataTable id="projects"
                             styleClass="data"
                             var="proj"
                             rowKey="#{proj}"
                             value="#{projectController.items}"
                             selection="#{projectController.current}"
                             selectionMode="single"
                             rows="8"
                             paginator="#{projectController.items.size() gt 8}"
                             >
                    <f:facet name="header">
                        <h:outputText value="Projects"></h:outputText>
                    </f:facet>
                    <p:column sortBy="#{proj.prjName}" filterBy="#{proj.prjName}">
                        <f:facet name="header">
                            <h:outputText value="Project Name"/>
                        </f:facet>
                        <h:outputText value="#{proj.prjName}"/>
                    </p:column>
                    <p:column sortBy="#{proj.prjDesc}" filterBy="#{proj.prjDesc}">
                        <f:facet name="header">
                            <h:outputText value="Project Name"/>
                        </f:facet>
                        <h:outputText value="#{proj.prjDesc}"/>
                    </p:column>
                    <p:column sortBy="#{proj.prjCreation}" filterBy="#{proj.prjCreation}">
                        <f:facet name="header">
                            <h:outputText value="Project Creation"/>
                        </f:facet>
                        <h:outputText value="#{proj.prjCreation}">
                        </h:outputText>
                    </p:column>
                    <p:column  sortBy="#{proj.projectHasUserList.size()}">
                        <f:facet name="header">
                            <h:outputText value="# Staff"/>
                        </f:facet>
                        <h:outputText value="#{proj.projectHasUserList.size()}"/>
                    </p:column>
                    <f:facet name="footer">
                        <h:outputText id="rowCount"
                                      value="Total number of records: #{projectController.items.size()}" />
                        <br/>
                        <p:commandButton ajax="false" action="#{projectController.prepareCreate}" value="New" icon="ui-icon-plus" rendered="#{empty projectController.items}"/>
                    </f:facet>
                </p:dataTable>
                <c:if test="#{userController.allowedGroups('2')}">
                    <p:contextMenu for="projects" >
                        <p:menuitem value="Edit" icon="ui-icon-pencil"   action="#{projectController.prepareEdit}" />
                        <p:menuitem value="Delete" icon="ui-icon-close" actionListener="#{projectController.destroy}" update=":form:"/>
                        <p:menuitem value="View" icon="ui-icon-search" action="#{projectController.prepareView}"/>
                        <p:menuitem value="New" icon="ui-icon-plus" action="#{projectController.prepareCreate}" />
                    </p:contextMenu>
                </c:if>
            </p:fieldset>
        </h:form>
    </ui:define>
</ui:composition>


